<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>书城</title>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/bootstrap3/css/bootstrap.css">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/bootstrap3/font-awesome-4.7.0/css/font-awesome.css"/>
</head>
<body>
<div class="container">
	<nav class="navbar navbar-default">
  <div class="container-fluid ">
    <div class="navbar-header navbar-right">
      <a class="navbar-brand " href="http://localhost:8080/cas_server/loginOutAll.jsp?appurl=<%=request.getRequestURL()%>"><b>登出<b>
      </a>
    </div>
  </div>
</nav>
<div class="row">
	<h2>添加书或库存</h2>
	<form action="${pageContext.request.contextPath}/addBookServlet" method="post">
		<table cellspacing="0" cellpadding="10" border="1">
			<tr>
				<td>书名</td>
				<td><input type="text" name="title"><a></a></td>
			</tr>
			<tr>
				<td>作者</td>
				<td><input type="text" name="author"></td>
			</tr>
			<tr>
				<td>价格</td>
				<td><input type="text" name="price"></td>
			</tr>
			<tr>
				<td>出版日期</td>
				<td><input type="text" name="pdate"></td>
			</tr>
			<tr>
				<td>增加的库存数</td>
				<td><input type="text" name="add_num"></td>
			</tr>
			<tr>
				<td colspan="2" align="center"><input type="submit" ></td>
			</tr>			
		</table>
	</form>
	</div>
</div>
<script type="text/javascript" src="${pageContext.request.contextPath}/bootstrap3/jquery.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/bootstrap3/js/bootstrap.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/bootstrap3/js/holder.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/bootstrap3/js/html5shiv.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/bootstrap3/js/css3-mediaqueries.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/bootstrap3/js/respond.min.js"></script>
<script type="text/javascript">
	$("input[name='title']").change(function(){
		var title=$("input[name='title']").val();
		var args={"time":new Date()};
		var url="${pageContext.request.contextPath}/checkBookNameServlet?title="+title;
		$.getJSON(url,args,function(data){
			if(data.title!="no-book"){
				$("input[name='title']").next().text("此书已存在 ,可添加库存")
				$("input[name='title']").next().css("color","red");
				readonly();
			}else{	
				$("input[name='title']").next().text("仓库中没有该书")
				$("input[name='title']").next().css("color","green");
				active();
			}
		});
	});
	function readonly(){
		$("input[type='text']").attr("readonly","readonly");		
		$("input[name='title']").attr("readonly",false);
		$("input[name='add_num']").attr("readonly",false);				
	}
	function active(){
		$("input[type='text']").attr("readonly",false);
	}
</script>
</body>
</html>